package org.despair2D.ui.core 
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import org.despair2D.renderer.IView;
	import org.despair2D.ui.DespairUI;
	
	import org.despair2D.core.ns_despair;
	use namespace ns_despair;
	
	
	/** 按下 **/
	[Event(name = "press", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 弹起 **/
	[Event(name = "release", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 滑上 **/
	[Event(name = "over", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 滑出 **/
	[Event(name = "leave", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 移动 **/
	[Event(name = "move", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 单击 **/
	[Event(name = "click", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 双击 **/
	[Event(name = "doubleClick", type = "org.despair2D.ui.events.ManipulateEvent")]
	
	/** 开始拖动 **/
	[Event(name = "startDrag", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	/** 停止拖动 **/
	[Event(name = "stopDrag", type = "org.despair2D.ui.events.ManipulateEvent")] 

	[Event(name = "killed", type = "org.despair2D.ui.events.ManipulateEvent")] 
	
	[Event(name = "interactiveChange", type = "org.despair2D.ui.events.InteractiveEvent")] 
	
	[Event(name = "visibleChange", type = "org.despair2D.ui.events.VisibleEvent")] 
	
	
	/** @inheritDoc **/
public class ComponentProxy implements IComponent
{
	
	
	//======================
	// View Property
	//======================
	
	
	final public function get name() : String { return view.name; }
	final public function set name( v:String ) : void { view.name = v; }
	
	
	public function get x () : Number{ return view.x; }
	public function set x ( v:Number ) : void { view.x = v; }
	
	
	public function get y () : Number{ return view.y; }
	public function set y ( v:Number ) : void 
	{
		view.y = v;
	}
	
	
	final public function get mouseX() : Number
	{
		return view.mouseX;
	}
	
	
	final public function get mouseY () : Number
	{
		return view.mouseY;
	}
	
	
	public function get width() : Number
	{
		return view.width
	}
	
	public function get height () : Number
	{
		return view.height
	}
	
	
	public function get rotation () : Number{ return view.rotation; }
	public function set rotation ( v:Number ) : void 
	{
		view.rotation = v;
	}
	
	public function get scaleX () : Number { return view.scaleX; }
	public function set scaleX ( v:Number ) : void 
	{
		view.scaleX = v;
	}
	
	public function get scaleY () : Number { return view.scaleY; }
	public function set scaleY ( v:Number ) : void 
	{
		view.scaleY = v;
	}
	
	final public function get alpha () : Number { return view.alpha; }
	final public function set alpha ( v:Number ) : void 
	{
		view.alpha = v;
	}
	
	final public function get visible () : Boolean { return view.visible; }
	final public function set visible ( b:Boolean ) : void 
	{
		view.visible = b;
	}

	
	public function get filters () : Array { return view.filters; }
	public function set filters ( v:Array ) : void 
	{
		view.filters = v;
	}
	
	public function get interactive () : Boolean { return view.interactive; }
	public function set interactive ( b:Boolean ) : void 
	{
		view.interactive = b;
	}

	
	
	public function move( x:Number, y:Number ) : void
	{
		view.move(x, y);
	}
	
	
	public function offset( tx:Number, ty:Number ) : void
	{
		view.offset(tx, ty);
	}
	
	
	final public function addEventListener( type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ) : void
	{
		view.addEventListener(type, listener, useCapture, priority, useWeakReference);
	}
	
	
	final public function removeEventListener( type:String, listener:Function, useCapture:Boolean = false ) : void
	{
		view.removeEventListener(type, listener, useCapture);
	}
	
	
	final public function dispatchEvent( event:Event ) : Boolean
	{
		return view.dispatchEvent(event);
	}

	
	final public function hasEventListener( type:String ) : Boolean
	{
		return view.hasEventListener(type);
	}
	
	
	final public function willTrigger( type:String ) : Boolean
	{
		return view.willTrigger(type);
	}
	
	
	final public function removeAllEventListeners() : void
	{
		view.removeAllEventListeners()
	}
	
	
	
	
	
	
	//======================
	// Component Property
	//======================
	
	
	/** 显示对象 **/
	public function get displayObject() : DisplayObject
	{
		return view as DisplayObject
	}
	
	
	/** 全局坐标点 **/
	final public function get globalPos() : Point
	{
		return (view as Component).globalPos
	}
	
	
	/** 图层 **/
	final public function get layer() : int
	{
		return (view as Component).layer
	}
	
	
	/** 滑鼠是否正在上面 **/
	public function get hovered() : Boolean
	{
		return false;
	}
	
	
	/** 是否被按下 **/
	public function get pressed() : Boolean
	{
		return false;
	}
	
	
	/** 是否拖动中 **/
	final public function get dragging() : Boolean
	{
		return Boolean(DespairUI.draggingObject == this)
	}
	
	
	/** 是否拖动中，并处于拖动范围内 **/
	final public function get draggingInBounds() : Boolean
	{
		return Boolean(DespairUI.draggingObject == this && UIManager.m_draggingInBounds)
	}
	
	
	/** 用户数据 **/
	final public function get userData() : Object{ return m_userData; }
	final public function set userData( v:Object ) : void
	{
		m_userData = v;
	}
	
	
	
	/**
	 * 移动至全局某点
	 * @param	gx
	 * @param	gy
	 */
	final public function moveInStage( gx:Number, gy:Number ) : void
	{
		(view as Component).moveInStage(gx, gy)
	}
	
	
	/**
	 * 开始拖动
	 * @param	lockCenter
	 * @param	bounds
	 */
	final public function startDrag( lockCenter:Boolean = false, bounds:Rectangle = null ) : void
	{
		UIManager.startDragComp(view as Component, lockCenter, bounds);
	}
	
	
	/**
	 * 杀死
	 */
	public function kill() : void
	{
		this.recycle();
	}	
	
	
	
	
	/**
	 * @inheritDoc
	 * 组件
	 */
	ns_despair function get view() : IView
	{
		return null;
	}

	
	/**
	 * @inheritDoc
	 * 回收
	 */
	ns_despair function recycle() : void
	{
		(view as Object).recycle()
		m_userData = null
	}
	
	
	
	ns_despair var m_userData:Object
	
}

}